<?php

namespace app\common\service;

use app\common\model\AdminLog as Model;
use app\common\util\WhereBuilder;

/**
 * 管理员日志 业务类
 */
class AdminLogService extends Service
{
    protected string $model_name = 'log';
    protected string $model_cname = '管理员日志';

    /**
     * 管理员分页
     */
    public function adminPage($param = [])
    {
        $param = $this->autoParams($param);

        $keyword = $this->pg('keyword');

        $where = WhereBuilder::builder()
            ->like('name|controller|action', $keyword)
            ->build();

        return (new Model)
            ->with([
                'admin' => function($query) {
                    $query->field(['id','login_name','real_name']);
                }
            ])
            ->where($where)
            ->order('id desc')
            ->hidden(['params', 'response'])
            ->paginate($this->tp6Page());
    }

    /**
     * 详情
     * @param $param
     * @return Model|mixed
     * @throws \Exception
     */
    public function detail($param = [])
    {
        $this->autoParams($param);

        $id = $this->req('id');
        $model = (new Model)
            ->with([
                'admin' => function($query) {
                    $query->field(['id','login_name','real_name']);
                }
            ])
            ->where('id', $id)
            ->find();

        return $model;
    }
}
